app.controller("addupdateFee",function($scope,$http, $stateParams,get,post,$rootScope,Md5,$state){
	//取消
	$scope.rement=function(){
		$state.go("home."+$stateParams.url,{page:$stateParams.page},{
						     		reload:true
						     	})
	}
	$scope.selects=function(){
		//科目
		get.list("dictionary/subjectDic").then(function(e){
				$scope.subjectDic = e
					//专业
			})
		//付款类型
		get.list("dictionary/paymentDic").then(function(e){
				$scope.paymentDic = e
			})
		//项目
		get.list("dictionary/project").then(function(e){
				$scope.project = e
			})
		//经办人
		get.list("dictionary/staff").then(function(e){
				$scope.dictionarystaff = e
			})
		
			//所属部门
			$scope.frMan={
						value:{
							diName:"请选择",
							diId:null
						}
					}
			//工作状态
			$scope.frType={
						value:{
							diName:"请选择",
							diId:null
						}
					}
			//专业
			$scope.projectId={
						value:{
							diName:"请选择",
							diId:null
						}
					}
			//户口性质
			$scope.staffId={
						value:{
							diName:"请选择",
							diId:null
						}
					}		
	
	}
	
		$scope.selects()
	setTimeout(function (){
	if($stateParams.id!=''){
		$scope.isshows=true
		get.list('fee/findOne',{frId:$stateParams.id}).then(function(e){
		$scope.pickertime=e.rrPayTime
		$scope.add={
		frMan:e.frMan,
		staffId:e.staffId,
		frSummary:e.frSummary,
		rrAcount:e.rrAcount,
		projectId:e.projectId,
		dateTime:e.rrPayTime, 
		frType:e.frType,
		projectName:null
		
	}
			
			//科目
	angular.forEach($scope.subjectDic,function(o){
		if(e.frMan==o.diId){
			$scope.frMan={
				value:o
			}
		}
	})
	//付款类型
	console.log($scope.paymentDic)
	angular.forEach($scope.paymentDic,function(o){
		console.log(e.frType)
		if(e.frType==o.diId){
			$scope.frType={
					value:o
			}
	
		}
	})
	//项目
	angular.forEach($scope.project,function(o){
		if(e.projectId==o.diId){
			$scope.projectId={
					value:o
			}
		}
	})
		//经办人
	angular.forEach($scope.dictionarystaff,function(o){
		if(e.staffId==o.diId){
			$scope.staffId={
				value:o
			}
		}
	})
		})
	}
	},200)
	$scope.add={
		frMan:null,
		staffId:null,
		frSummary:'',
		rrAcount:null,
		dateTime:null,
		projectId:null,
		frType:null,
		projectName:null
		
	}
	$scope.sub=function(val){
	
		$scope.add.dateTime=$scope.add.entryTime||$scope.add.dateTime
		if($scope.add.frMan!=null){
			$scope.add.frMan=$scope.add.frMan.diId||$scope.add.frMan
		}
		if($scope.add.frType!=null){
			$scope.add.frType=$scope.add.frType.diId||$scope.add.frType
		}
		if($scope.add.projectId!=null){
			$scope.add.projectId=$scope.add.projectId.diId||$scope.add.projectId
		}
		if($scope.add.staffId!=null){
			$scope.add.staffId=$scope.add.staffId.diId||$scope.add.staffId
		}
		$scope.add.frMan=$scope.add.frMan||''
		$scope.add.staffId=$scope.add.staffId||''
		$scope.add.projectId=$scope.add.projectId||''
		if($stateParams.id!=''){
				$scope.add.frId=$stateParams.id
				post.list("fee/update",$scope.add).then(function(o){
						$state.go("home."+$stateParams.url,{page:$stateParams.page},{
						     		reload:true
						     	})
				})
			}else{
				post.list("fee/add",$scope.add).then(function(o){
						$state.go("home."+$stateParams.url,{page:$stateParams.page},{
						     		reload:true
						     	})
				})
				
			}
			
			
		
		
	}
	
})
